package com.rzjm.exercise.common.schedule.listener;

import com.rzjm.exercise.common.constant.Constant;
import com.rzjm.exercise.module.domain.Parameter;
import com.rzjm.exercise.module.service.ParameterService;
import com.rzjm.exercise.common.schedule.quartz.QuartzManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.rzjm.exercise.sys.core.job.service.JobService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@Order(value = 1)
public class ScheduleJobListener implements CommandLineRunner {

	@Autowired
	JobService scheduleJobService;

	@Autowired
    QuartzManager quartzManager;

	@Autowired
	private ParameterService parameterService;

	@Autowired
	protected RedisTemplate<String, Object> redisTemplate;

	@Override
	public void run(String... arg0) throws Exception {
		try {
			System.out.println("ScheduleJobListener ");
			Parameter parameter = parameterService.selectByUniqueColumn("is_default","1");
			if(parameter !=null){
				redisTemplate.opsForValue().set(Constant.PARAMETER, parameter);
			}
			scheduleJobService.initSchedule();
		} catch (Exception e) {
			log.error(e.toString());
		}
	}

}
